using Boo.Lang;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class autocalibrateonoff : MonoBehaviour
{
	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024Block_0024266 : GenericGenerator<WaitForSeconds>
	{
		internal autocalibrateonoff _0024self__0024268;

		public _0024Block_0024266(autocalibrateonoff self_)
		{
			_0024self__0024268 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024268);
		}
	}

	private float w;

	private float h;

	public GUISkin skin;

	public AudioClip clip;

	public int autocalibrate;

	public int vibration;

	public int musics;

	public int backwards;

	public int left;

	public int touch;

	public int shadow;

	public int tilt;

	public int fps;

	public int fpsV;

	public int hqgraphics;

	public int fpslimit;

	public int aa;

	public int vignetting;

	public int specular;

	public int lowres;

	public int trails;

	public int Bit;

	public bool togglecalib;

	public bool vibrate;

	public bool music;

	public bool backwardson;

	public bool lefthanded;

	public bool touchcontrol;

	public bool touchcontrolA;

	public bool tiltcontrol;

	public bool shadowon;

	public bool tilton;

	public bool fpson;

	public bool hqgraphicson;

	public bool fpslimiton;

	public bool lowreson;

	public bool trailson;

	public bool Biton;

	public bool aaon;

	public bool vignettingOn;

	public bool state;

	public GameObject audioplayer;

	public float musicvolume;

	public float sensitivity;

	public GameObject musicvol;

	public bool showvideo;

	public bool showcontrol;

	public bool showaudio;

	public OptionsButtons3D buttons;

	private float originalWidth;

	private float originalHeight;

	private Vector2 scale;

	private bool blocked;

	public Vector2 scrollPosition;

	public int numRows;

	public Vector2 rowSize;

	public Vector2 windowMargin;

	public Vector2 listMargin;

	private Rect windowRect;

	public int tune;

	public float fStopThreshold;

	public float coef;

	public float smoothcoef;

	private float fResistanceFactor;

	private bool bTranslating;

	private Vector3 v3StartPos;

	private Vector3 v3LastPos;

	private Vector3 v3Delta;

	private Vector3 v3Startb;

	private float fStartTime;

	private float scrollPositionL;

	public autocalibrateonoff()
	{
		autocalibrate = 1;
		vibration = 1;
		musics = 1;
		vignetting = 1;
		trails = 1;
		Bit = 1;
		togglecalib = true;
		vibrate = true;
		music = true;
		tiltcontrol = true;
		trailson = true;
		Biton = true;
		vignettingOn = true;
		state = true;
		musicvolume = 0.9f;
		sensitivity = 1f;
		showvideo = true;
		showcontrol = true;
		showaudio = true;
		originalWidth = 640f;
		originalHeight = 360f;
		tune = 20000;
		fStopThreshold = 1f;
		coef = 850f;
		smoothcoef = 0.05f;
		fResistanceFactor = 0.9f;
	}

	public void CheckRes()
	{
		if (Screen.height > 700)
		{
			numRows = tune / (Mathf.Clamp(Screen.height, 0, 1000) + 50);
		}
		else
		{
			numRows = tune / (Mathf.Clamp(Screen.height, 0, 1000) + 380);
		}
		if (Screen.width > 640)
		{
			scale.x = (float)Screen.width / originalWidth;
			scale.y = (float)Screen.height / originalHeight;
		}
		else
		{
			scale.x = 1f;
			scale.y = 1f;
		}
		if (Screen.width > 1020)
		{
			scale.x = 1024f / originalWidth;
			scale.y = 600f / originalHeight;
		}
	}

	public void Start()
	{
		w = PlayerPrefs.GetInt("Width");
		h = PlayerPrefs.GetInt("Height");
		autocalibrate = PlayerPrefs.GetInt("AutoCalibrate");
		musicvol = GameObject.Find("audioplayer(Clone)");
		musicvolume = PlayerPrefs.GetFloat("MusicVolume");
		fpsV = PlayerPrefs.GetInt("FPSLimit");
		left = PlayerPrefs.GetInt("LeftHanded");
		touch = PlayerPrefs.GetInt("TouchControl");
		fps = PlayerPrefs.GetInt("FPS");
		hqgraphics = PlayerPrefs.GetInt("HQGraphics");
		fpslimit = PlayerPrefs.GetInt("FPSLimitOn");
		lowres = PlayerPrefs.GetInt("LowRes");
		trails = PlayerPrefs.GetInt("Trails");
		Bit = PlayerPrefs.GetInt("32Bit");
		aa = PlayerPrefs.GetInt("MSAA");
		sensitivity = PlayerPrefs.GetFloat("Sensitivity");
		vignetting = PlayerPrefs.GetInt("Vignetting");
		buttons = (gameObject.GetComponent("OptionsButtons3D") as OptionsButtons3D);
		if (autocalibrate == 1)
		{
			togglecalib = true;
		}
		else
		{
			togglecalib = false;
		}
		if (left == 0)
		{
			lefthanded = false;
		}
		else
		{
			lefthanded = true;
		}
		if (touch == 0)
		{
			touchcontrol = false;
			touchcontrolA = false;
			tiltcontrol = true;
		}
		else if (touch == 1)
		{
			touchcontrol = true;
			touchcontrolA = false;
			tiltcontrol = false;
		}
		else if (touch == 2)
		{
			touchcontrol = false;
			touchcontrolA = true;
			tiltcontrol = false;
		}
		if (fps == 0)
		{
			fpson = false;
		}
		else
		{
			fpson = true;
		}
		if (hqgraphics == 0)
		{
			hqgraphicson = false;
		}
		else
		{
			hqgraphicson = true;
		}
		if (fpslimit == 0)
		{
			fpslimiton = false;
		}
		else
		{
			fpslimiton = true;
		}
		if (shadow == 1)
		{
			shadowon = true;
		}
		if (lowres == 0)
		{
			lowreson = false;
		}
		else
		{
			lowreson = true;
		}
		if (trails == 0)
		{
			trailson = false;
		}
		else
		{
			trailson = true;
		}
		if (Bit == 0)
		{
			Biton = false;
		}
		else
		{
			Biton = true;
		}
		if (aa == 0)
		{
			aaon = false;
		}
		else
		{
			aaon = true;
		}
		if (vignetting == 0)
		{
			vignettingOn = false;
		}
		else
		{
			vignettingOn = true;
		}
		vibration = PlayerPrefs.GetInt("Vibration");
		if (vibration == 1)
		{
			vibrate = true;
		}
		else
		{
			vibrate = false;
		}
		musics = PlayerPrefs.GetInt("Music");
		if (musics == 1)
		{
			music = true;
		}
		else
		{
			music = false;
		}
	}

	public void OnGUI()
	{
		GUI.skin = skin;
		if (showvideo)
		{
			buttons.state = true;
			windowRect = new Rect(windowMargin.x, windowMargin.y, (float)Screen.width - 2f * windowMargin.x, (float)Screen.height - 2f * windowMargin.y);
			GUI.Window(0, windowRect, DoWindowG, "Graphics");
		}
		if (showcontrol)
		{
			buttons.state = true;
			windowRect = new Rect(windowMargin.x, windowMargin.y, (float)Screen.width - 2f * windowMargin.x, (float)Screen.height - 2f * windowMargin.y);
			GUI.Window(0, windowRect, DoWindowC, "Controls");
		}
		if (showaudio)
		{
			buttons.state = true;
			windowRect = new Rect(windowMargin.x, windowMargin.y, (float)Screen.width - 2f * windowMargin.x, (float)Screen.height - 2f * windowMargin.y);
			GUI.Window(0, windowRect, DoWindowA, "Audio");
		}
	}

	public void Update()
	{
		if (PlayerPrefs.GetInt("FPSLimitOn") == 1)
		{
			Application.targetFrameRate = PlayerPrefs.GetInt("FPSLimit");
		}
		else
		{
			Application.targetFrameRate = 60;
		}
		PlayerPrefs.SetFloat("MusicVolume", musicvolume);
		PlayerPrefs.SetFloat("Sensitivity", sensitivity);
		if ((bool)musicvol)
		{
			musicvol.GetComponent<AudioSource>().volume = musicvolume;
		}
		PlayerPrefs.SetInt("FPSLimit", fpsV);
		if (togglecalib)
		{
			autocalibrate = 1;
		}
		else
		{
			autocalibrate = 0;
		}
		PlayerPrefs.SetInt("AutoCalibrate", autocalibrate);
		if (vibrate)
		{
			vibration = 1;
		}
		else
		{
			vibration = 0;
		}
		PlayerPrefs.SetInt("Vibration", vibration);
		if (lefthanded)
		{
			left = 1;
		}
		else
		{
			left = 0;
		}
		PlayerPrefs.SetInt("LeftHanded", left);
		if (fpson)
		{
			fps = 1;
		}
		else
		{
			fps = 0;
		}
		PlayerPrefs.SetInt("FPS", fps);
		if (hqgraphicson)
		{
			hqgraphics = 1;
		}
		else
		{
			hqgraphics = 0;
		}
		PlayerPrefs.SetInt("HQGraphics", hqgraphics);
		QualitySettings.SetQualityLevel(hqgraphics, applyExpensiveChanges: true);
		if (fpslimiton)
		{
			fpslimit = 1;
		}
		else
		{
			fpslimit = 0;
		}
		PlayerPrefs.SetInt("FPSLimitOn", fpslimit);
		if (aaon)
		{
			aa = 1;
		}
		else
		{
			aa = 0;
		}
		QualitySettings.antiAliasing = aa * 2;
		PlayerPrefs.SetInt("MSAA", aa);
		if (vignettingOn)
		{
			vignetting = 1;
		}
		else
		{
			vignetting = 0;
		}
		PlayerPrefs.SetInt("Vignetting", vignetting);
		if (lowreson)
		{
			lowres = 1;
			Screen.SetResolution(PlayerPrefs.GetInt("WidthLow"), PlayerPrefs.GetInt("HeightLow"), fullscreen: true);
		}
		else
		{
			lowres = 0;
			Screen.SetResolution((int)w, (int)h, fullscreen: true);
		}
		PlayerPrefs.SetInt("LowRes", lowres);
		if (trailson)
		{
			trails = 1;
		}
		else
		{
			trails = 0;
		}
		PlayerPrefs.SetInt("Trails", trails);
		if (Biton)
		{
			Bit = 1;
			Handheld.use32BitDisplayBuffer = true;
		}
		else
		{
			Bit = 0;
			Handheld.use32BitDisplayBuffer = false;
		}
		PlayerPrefs.SetInt("32Bit", Bit);
		if (music)
		{
			musics = 1;
			if ((bool)GameObject.Find("audioplayer(Clone)"))
			{
				UnityEngine.Object.Destroy(GameObject.Find("audioplayer(Clone)"));
			}
		}
		else
		{
			musics = 1;
			if (!GameObject.Find("audioplayer(Clone)"))
			{
				UnityEngine.Object.Instantiate(audioplayer);
				musicvol = GameObject.Find("audioplayer(Clone)");
			}
		}
		PlayerPrefs.SetInt("Music", musics);
		if (Input.GetMouseButtonDown(0))
		{
			bTranslating = false;
			v3StartPos = UnityEngine.Input.GetTouch(0).position;
			v3LastPos = v3StartPos;
			fStartTime = Time.time;
		}
		if (Input.GetMouseButtonUp(0))
		{
			v3Delta = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = v3Delta;
				fStartTime = Time.time;
			}
			v3Delta = (v3Delta - v3StartPos) / (Time.time - fStartTime);
			bTranslating = true;
			if (!(Mathf.Abs(v3Delta.y) >= 300f))
			{
				v3Delta.y = 0f;
			}
		}
		if (Input.GetMouseButton(0))
		{
			Vector3 a = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = UnityEngine.Input.GetTouch(0).position;
				v3LastPos = v3StartPos;
				fStartTime = Time.time;
			}
			Vector2 vector = a - v3LastPos;
			vector.x = 0f;
			vector.y /= h;
			scrollPosition.y += vector.y * coef;
			scrollPositionL = scrollPosition.y;
			v3LastPos = a;
		}
		if (bTranslating && !(v3Delta.magnitude <= 10f))
		{
			scrollPositionL += v3Delta.y * smoothcoef;
			v3Delta *= fResistanceFactor;
			if (!(v3Delta.magnitude >= fStopThreshold))
			{
				bTranslating = false;
			}
		}
		if (!Input.GetMouseButton(0))
		{
			scrollPosition.y = Mathf.Lerp(scrollPosition.y, scrollPositionL, Time.deltaTime * 8f);
		}
	}

	public IEnumerator Block()
	{
		return new _0024Block_0024266(this).GetEnumerator();
	}

	public void DoWindowG(int windowID)
	{
		Vector2 vector = new Vector2(windowRect.width - 2f * listMargin.x, windowRect.height - 2f * listMargin.y);
		Rect position = new Rect(listMargin.x, listMargin.y, vector.x, vector.y);
		Rect viewRect = new Rect(0f, 0f, rowSize.x, (float)numRows * rowSize.y);
		scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect, alwaysShowHorizontal: false, alwaysShowVertical: false);
		if (Input.GetMouseButtonUp(0))
		{
			float y = v3Startb.y;
			Vector3 mousePosition = UnityEngine.Input.mousePosition;
			if (!(Mathf.Abs(y - mousePosition.y) <= 10f))
			{
				GUI.enabled = false;
			}
		}
		fpson = GUILayout.Toggle(fpson, "FPS Counter", GUILayout.Height(Screen.height / 18 + 10));
		GUILayout.Label("Show framerate in-game");
		hqgraphicson = GUILayout.Toggle(hqgraphicson, "High Quality Graphics", GUILayout.Height(Screen.height / 18 + 10));
		GUILayout.Label("Realtime shadows and specular lighting, looks a lot better but may cause slowdown on older devices.");
		GUILayout.Label("(NOTE: Due to an unknown reason the shadows may disappear until restarting the game)");
		aaon = GUILayout.Toggle(aaon, "Anti-Aliasing", GUILayout.Height(Screen.height / 18 + 10));
		GUILayout.Label("Add 2X anti-aliasing (MSAA) smoothes pixelated edges of objects, some devices may not support this.");
		Biton = GUILayout.Toggle(Biton, "32-Bit Display Buffer", GUILayout.Height((float)Screen.height / 18f + 10f));
		GUILayout.Label("Enable 32-Bit color values, fixes possible color banding and makes transparent things look better but may be a bit slower.");
		fpslimiton = GUILayout.Toggle(fpslimiton, "FPS Limiter", GUILayout.Height((float)Screen.height / 18f + 10f));
		GUILayout.Label("Limit framerate to chosen value, not normally needed (unless you want to save battery).");
		fpsV = (int)GUILayout.HorizontalSlider(fpsV, 30f, 70f);
		GUI.contentColor = new Color(0f, 0.69f, 1f);
		if (fpslimiton)
		{
			GUILayout.Label("FPS : " + fpsV);
		}
		else
		{
			GUILayout.Label("FPS : No Limit");
		}
		GUI.contentColor = Color.white;
		if (GUILayout.Button("Close", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			Close();
		}
		GUI.EndScrollView();
		if (Input.GetMouseButtonDown(0))
		{
			v3Startb = UnityEngine.Input.mousePosition;
		}
	}

	public void DoWindowA(int windowID)
	{
		Vector2 vector = new Vector2(windowRect.width - 2f * listMargin.x, windowRect.height - 2f * listMargin.y);
		Rect position = new Rect(listMargin.x, listMargin.y, vector.x, vector.y);
		Rect viewRect = new Rect(0f, 0f, rowSize.x, (float)numRows * rowSize.y);
		scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect, alwaysShowHorizontal: false, alwaysShowVertical: false);
		if (Input.GetMouseButtonUp(0))
		{
			float y = v3Startb.y;
			Vector3 mousePosition = UnityEngine.Input.mousePosition;
			if (!(Mathf.Abs(y - mousePosition.y) <= 10f))
			{
				GUI.enabled = false;
			}
		}
		music = GUILayout.Toggle(music, "Music", GUILayout.Height((float)Screen.height / 18f + 10f));
		GUILayout.Label("No music yet... Maybe coming some time");
		musicvolume = GUILayout.HorizontalSlider(musicvolume, 0f, 1f);
		GUI.contentColor = new Color(0f, 0.69f, 1f);
		GUILayout.Label("Volume: " + (musicvolume * 100f).ToString("f0") + "%");
		GUI.contentColor = Color.white;
		if (GUILayout.Button("Close", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			Close();
		}
		GUI.EndScrollView();
		if (Input.GetMouseButtonDown(0))
		{
			v3Startb = UnityEngine.Input.mousePosition;
		}
	}

	public void DoWindowC(int windowID)
	{
		Vector2 vector = new Vector2(windowRect.width - 2f * listMargin.x, windowRect.height - 2f * listMargin.y);
		Rect position = new Rect(listMargin.x, listMargin.y, vector.x, vector.y);
		Rect viewRect = new Rect(0f, 0f, rowSize.x, (float)numRows * rowSize.y);
		scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect, alwaysShowHorizontal: false, alwaysShowVertical: false);
		if (Input.GetMouseButtonUp(0))
		{
			float y = v3Startb.y;
			Vector3 mousePosition = UnityEngine.Input.mousePosition;
			if (!(Mathf.Abs(y - mousePosition.y) <= 10f))
			{
				GUI.enabled = false;
			}
		}
		if (GUILayout.Button("Calibrate Accelerometer", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
			Vector3 acceleration = Input.acceleration;
			PlayerPrefs.SetFloat("CalibrateY", 0f - acceleration.y);
			Vector3 acceleration2 = Input.acceleration;
			PlayerPrefs.SetFloat("CalibrateX", acceleration2.x);
		}
		togglecalib = GUILayout.Toggle(togglecalib, "AutoCalibrate", GUILayout.Height(Screen.height / 18 + 10));
		GUILayout.Label("Calibrate the accelerometer at every match start");
		sensitivity = GUILayout.HorizontalSlider(sensitivity, 0.6f, 2f);
		GUI.contentColor = new Color(0f, 0.69f, 1f);
		GUILayout.Label("Sensitivity (default 1.0): " + sensitivity.ToString("f1"));
		GUI.contentColor = Color.white;
		GUILayout.Label(string.Empty);
		GUILayout.Label("Control Style:");
		changetilt(GUILayout.Toggle(tiltcontrol, "Tilt Control", GUILayout.Height(Screen.height / 18 + 10)));
		changetouch2(GUILayout.Toggle(touchcontrolA, "On-Screen Joystick", GUILayout.Height(Screen.height / 18 + 10)));
		changetouch1(GUILayout.Toggle(touchcontrol, "Swipe Control", GUILayout.Height(Screen.height / 18 + 10)));
		GUILayout.Label(string.Empty);
		lefthanded = GUILayout.Toggle(lefthanded, "Left-Handed", GUILayout.Height(Screen.height / 18 + 10));
		GUILayout.Label("Swap the launcher 180 degrees to use with left hand");
		vibrate = GUILayout.Toggle(vibrate, "Vibration", GUILayout.Height(Screen.height / 18 + 10));
		GUILayout.Label("Uses the vibration motor for collision effects. (It may be a bit too powerful on some devices)");
		if (GUILayout.Button("Close", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			Close();
		}
		GUI.EndScrollView();
		if (Input.GetMouseButtonDown(0))
		{
			v3Startb = UnityEngine.Input.mousePosition;
		}
	}

	public void Close()
	{
		if (showaudio)
		{
			showaudio = false;
		}
		else if (showvideo)
		{
			showvideo = false;
		}
		else if (showcontrol)
		{
			showcontrol = false;
		}
		AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
		scrollPosition.y = 0f;
		buttons.state = false;
	}

	private void changetilt(bool newvalue)
	{
		if (newvalue)
		{
			touchcontrol = false;
			touchcontrolA = false;
		}
		tiltcontrol = newvalue;
		if (tiltcontrol)
		{
			PlayerPrefs.SetInt("TouchControl", 0);
		}
		if (touchcontrol)
		{
			PlayerPrefs.SetInt("TouchControl", 1);
		}
		if (touchcontrolA)
		{
			PlayerPrefs.SetInt("TouchControl", 2);
		}
	}

	private void changetouch1(bool newvalue)
	{
		if (newvalue)
		{
			tiltcontrol = false;
			touchcontrolA = false;
		}
		touchcontrol = newvalue;
		if (tiltcontrol)
		{
			PlayerPrefs.SetInt("TouchControl", 0);
		}
		if (touchcontrol)
		{
			PlayerPrefs.SetInt("TouchControl", 1);
		}
		if (touchcontrolA)
		{
			PlayerPrefs.SetInt("TouchControl", 2);
		}
	}

	private void changetouch2(bool newvalue)
	{
		if (newvalue)
		{
			tiltcontrol = false;
			touchcontrol = false;
		}
		touchcontrolA = newvalue;
		if (tiltcontrol)
		{
			PlayerPrefs.SetInt("TouchControl", 0);
		}
		if (touchcontrol)
		{
			PlayerPrefs.SetInt("TouchControl", 1);
		}
		if (touchcontrolA)
		{
			PlayerPrefs.SetInt("TouchControl", 2);
		}
	}

	public void Main()
	{
		InvokeRepeating("CheckRes", 0f, 0.5f);
	}
}
